﻿using System;
using System.Windows.Forms;

namespace Outlook.WorkItems.Extension.Controls
{
    public partial class SelectLibrairyForm : Form
    {
        public string Path
        {
            get
            {
                TreeNode node = teamTreeViewUC1.treeView1.SelectedNode;
                string path = "";
                if (node is DocumentLibrairyNode)
                {
                    path = node.Tag.ToString();
                    path = path.Substring(0, path.LastIndexOf("/Forms"));
                }
                else if (node is FolderNode)
                {
                    FolderNode fNode = node as FolderNode;
                    string doc = fNode.DocumentLibrairyNode.Tag.ToString();
                    doc = doc.Substring(0, doc.LastIndexOf("/Forms"));
                    string folder = node.Tag.ToString();
                    path = doc + folder.Substring(folder.IndexOf("/"), folder.Length - folder.IndexOf("/"));
                }
                return path;
            }
        }

        public SelectLibrairyForm()
        {
            InitializeComponent();
        }

        public SelectLibrairyForm(string teamProjectName)
            :this()
        {
            teamTreeViewUC1.TeamProjectName = teamProjectName;
        }

        private void SelectLibrairyForm_Load(object sender, EventArgs e)
        {
            teamTreeViewUC1.InitTreeView();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (teamTreeViewUC1.treeView1.SelectedNode == null || !(teamTreeViewUC1.treeView1.SelectedNode is DocumentLibrairyNode || teamTreeViewUC1.treeView1.SelectedNode is FolderNode))
                MessageBox.Show("Select a destination document librairy or a folder");
            else
            {
                DialogResult = DialogResult.OK;
                Close();
            }
            
        }
    }
}
